package com.ymm.spark.config;

import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author zhangj
 * @date 2019/10/25
 * 配置管理组件,读取配置文件
 */
@Slf4j
public class ConfigurationManager {

	private static Properties prop = new Properties();

	static {
		try {
			InputStream in = ConfigurationManager.class.getClassLoader()
					.getResourceAsStream("ymm.properties");
			prop.load(in);
		} catch (IOException e) {
			log.error("加载配置文件出错:{}", e.getMessage(), e);
		}

	}

	public static String getProperty(String key) {
		return prop.getProperty(key);
	}

	public static Integer getInteger(String key) {
		String value = getProperty(key);
		try {
			return Integer.valueOf(value);
		} catch (NumberFormatException e) {
			log.error(e.getMessage(), e);
		}
		return 0;
	}

	public static Boolean getBoolean(String key) {
		String value = getProperty(key);
		try {
			return Boolean.valueOf(value);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public static Long getLong(String key) {
		String value = getProperty(key);
		try {
			return Long.valueOf(value);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0L;
	}
}
